package com.example.leetcode.leetcode.hot100;

import com.example.leetcode.leetcode.list.ListNode;


/**
 * @author haitao
 * @date 2021/7/22 2:02 下午
 * <p>
 * 查找两个链表相交的节点
 * set 时间复杂度m+n
 * 双指针解法更优
 */
public class Solution160 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode pA= headA, pB =headB;
        while (pA!=pB){
            pA = pA!= null ? pA.next: headB;
            pB = pB!= null ? pB.next: headA;
        }
        return pA;
    }
}
